home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / util / moni / Scout-src.lha / source / objects / scout_commodity_detail.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-09-17  |  10.5 KB  |  282 lines

  1. /**
  2.  * Scout - The Amiga System Monitor
  3.  *
  4.  *------------------------------------------------------------------
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * You must not use this source code to gain profit of any kind!
  21.  *
  22.  *------------------------------------------------------------------
  23.  *
  24.  * @author Andreas Gelhausen
  25.  * @author Richard Körber <rkoerber@gmx.de>
  26.  */
  27.  
  28. #include "system_headers.h"
  29.  
  30. extern UBYTE *GetCxNodeType( UBYTE type );
  31.  
  32. static struct LongFlag brokerFlags[] = {
  33.     { 1,             "<unknown>",     "%00000001" },
  34.     { COF_ACTIVE,    "COF_ACTIVE",    "%00000010" },
  35.     { COF_SHOW_HIDE, "COF_SHOW_HIDE", "%00000100" },
  36.     { 0,             NULL,            NULL}
  37. };
  38.  
  39. static __asm __saveds LONG cxsublist_con2func(register __a2 Object *obj, register __a1 struct NList_ConstructMessage *msg, register __a0 struct Hook *hook)
  40. {
  41.     return AllocListEntry(msg->pool, msg->entry, sizeof(struct CxSubEntry));
  42. }
  43.  
  44. MakeHook(cxsublist_con2hook, cxsublist_con2func);
  45.  
  46. static __asm __saveds LONG cxsublist_des2func(register __a2 Object *obj, register __a1 struct NList_DestructMessage *msg, register __a0 struct Hook *hook)
  47. {
  48.     FreeListEntry(msg->pool, &msg->entry);
  49.  
  50.     return 0;
  51. }
  52.  
  53. MakeHook(cxsublist_des2hook, cxsublist_des2func);
  54.  
  55. static __asm __saveds LONG cxsublist_dsp2func(register __a2 Object *obj, register __a1 struct NList_DisplayMessage *msg, register __a0 struct Hook *hook)
  56. {
  57.     struct CxSubEntry *cxse = (struct CxSubEntry *)msg->entry;
  58.  
  59.     if (cxse) {
  60.         msg->strings[0] = cxse->cxse_Address;
  61.         msg->strings[1] = cxse->cxse_Type;
  62.         msg->strings[2] = cxse->cxse_Pri;
  63.     } else {
  64.         msg->strings[0] = MUIX_B "Address";
  65.         msg->strings[1] = MUIX_B "ln_Type";
  66.         msg->strings[2] = MUIX_B "ln_Pri";
  67.     }
  68.  
  69.     return 0;
  70. }
  71.  
  72. MakeHook(cxsublist_dsp2hook, cxsublist_dsp2func);
  73.  
  74. static void SetDetails( struct IClass *cl,
  75.                         Object *obj,
  76.                         struct CxEntry *cxe )
  77. {
  78.     struct CommoditiesDetailWinData *cdwd = INST_DATA(cl, obj);
  79.     BOOL found = FALSE;
  80.     struct MsgPort *cxport;
  81.  
  82.     if (cxport = CreateMsgPort()) {
  83.         struct NewBroker cxnewbroker = { NB_VERSION, "« Scout Dummy »", "« Scout Dummy »", "Dummy Broker", 0, 0, 0, NULL, 0 };
  84.         struct PrivateCxObj *cxbroker;
  85.  
  86.         cxnewbroker.nb_Port = cxport;
  87.  
  88.         if (cxbroker = (struct PrivateCxObj *)CxBroker(&cxnewbroker, NULL)) {
  89.             struct List *cxlist;
  90.             struct PrivateCxObj *mco;
  91.  
  92.             Forbid();
  93.  
  94.             cxlist = FindListOfNode((struct Node *)cxbroker);
  95.             ITERATE_LIST(cxlist, struct PrivateCxObj *, mco) {
  96.                 if (mco == cxe->cxe_Addr) {
  97.                     found = TRUE;
  98.                     break;
  99.                 }
  100.             }
  101.  
  102.             if (found) {
  103.                 struct Node *node;
  104.                 UBYTE flags[16];
  105.                 struct MinList tmplist;
  106.                 struct CxSubEntry *cxse, *_cxse;
  107.  
  108.                 Flags2BinStr(mco->mco_Flags, flags, sizeof(flags));
  109.  
  110.                 GetTaskName(mco->mco_Task, cdwd->cdwd_CxTaskName, sizeof(cdwd->cdwd_CxTaskName));
  111.                 MySetContents(cdwd->cdwd_CxSubMoreText[0], "%s", mco->mco_Name);
  112.                 MySetContents(cdwd->cdwd_CxSubMoreText[1], "%s", mco->mco_Title);
  113.                 MySetContents(cdwd->cdwd_CxSubMoreText[2], "%s", mco->mco_Descr);
  114.                 MySetContents(cdwd->cdwd_CxSubMoreText[3], MUIX_R "$%08lx\n" MUIX_C "%s\n%ld\n" MUIX_R "$%08lx\n$%08lx", mco, GetCxNodeType(CxObjType((CxObj *)mco)), mco->mco_Node.ln_Pri, mco->mco_Task, mco->mco_Port);
  115.                 MySetContents(cdwd->cdwd_CxSubMoreText[4], MUIX_B "%s", flags);
  116.                 MySetContentsHealed(cdwd->cdwd_CxSubMoreText[5], "%s", cdwd->cdwd_CxTaskName);
  117.  
  118.                 NewList((struct List *)&tmplist);
  119.  
  120.                 ApplicationSleep(TRUE);
  121.  
  122.                 set(cdwd->cdwd_CxSubList, MUIA_NList_Quiet, TRUE);
  123.                 DoMethod(cdwd->cdwd_CxSubList, MUIM_NList_Clear);
  124.  
  125.                 Forbid();
  126.  
  127.                 ITERATE_LIST(&mco->mco_SubList, struct Node *, node) {
  128.                     if (cxse = AllocVec(sizeof(struct CxSubEntry), MEMF_PUBLIC)) {
  129.                         _snprintf(cxse->cxse_Address, sizeof(cxse->cxse_Address), "$%08lx", node);
  130.                         stccpy(cxse->cxse_Type, GetCxNodeType(CxObjType((CxObj *)node)), sizeof(cxse->cxse_Type));
  131.                         _snprintf(cxse->cxse_Pri, sizeof(cxse->cxse_Pri), "%4ld", node->ln_Pri);
  132.  
  133.                         AddTail((struct List *)&tmplist, (struct Node *)cxse);
  134.                     }
  135.                 }
  136.  
  137.                 Permit();
  138.  
  139.                 ITERATE_CHANGING_LIST(&tmplist, struct CxSubEntry *, cxse, _cxse) {
  140.                     InsertBottomEntry(cdwd->cdwd_CxSubList, cxse);
  141.                     FreeVec(cxse);
  142.                 }
  143.  
  144.                 set(cdwd->cdwd_CxSubList, MUIA_NList_Quiet, FALSE);
  145.  
  146.                 ApplicationSleep(FALSE);
  147.  
  148.                 set(obj, MUIA_Window_Title, MyGetChildWindowTitle("COMMODITY", cxe->cxe_Name, cdwd->cdwd_Title, sizeof(cdwd->cdwd_Title)));
  149.             }
  150.  
  151.             Permit();
  152.  
  153.             DeleteCxObjAll((CxObj *)cxbroker);
  154.         }
  155.  
  156.         DeleteMsgPort(cxport);
  157.     }
  158. }
  159.  
  160. static ULONG __saveds mNew( struct IClass *cl,
  161.                             Object *obj,
  162.                             struct opSet *msg )
  163. {
  164.     APTR cxmoretext[6], cxsublist;
  165.  
  166.     if (obj = (Object *)DoSuperNew(cl, obj,
  167.         MUIA_HelpNode, ClassesText,
  168.         MUIA_Window_ID, MakeID('.','C','X','X'),
  169.         WindowContents, VGroup,
  170.  
  171.             Child, ColGroup(2),
  172.                 Child, MyLabel2("Name:"),
  173.                 Child, cxmoretext[0] = MyTextObject(),
  174.                 Child, MyLabel2("Title:"),
  175.                 Child, cxmoretext[1] = MyTextObject(),
  176.                 Child, MyLabel2("Descr:"),
  177.                 Child, cxmoretext[2] = MyTextObject(),
  178.             End,
  179.             Child, HGroup, MUIA_Group_SameWidth, TRUE,
  180.                 Child, ColGroup(2),
  181.                     Child, MyLabel2("Address:\nType:\nPri:\nTask:\nPort:"),
  182.                     Child, cxmoretext[3] = MyTextObject2(),
  183.                     Child, MyLabel2("Flags:"),
  184.                     Child, cxmoretext[4] = MakeButton(""),
  185.                 End,
  186.                 Child, ColGroup(2),
  187.                     Child, MyLabel2("\nSub CxObj:\n\n\n\n"),
  188.                     Child, cxsublist = MyNListviewObject(MakeID('.','C','L','V'), "BAR,BAR P=" MUIX_C ",BAR P=" MUIX_R, &cxsublist_con2hook, &cxsublist_des2hook, &cxsublist_dsp2hook, NULL, FALSE),
  189.                 End,
  190.             End,
  191.             Child, HGroup,
  192.                 Child, MyLabel2("TaskName:"),
  193.                 Child, cxmoretext[5] = MyTextObject(),
  194.             End,
  195.         End,
  196.         TAG_MORE, msg->ops_AttrList))
  197.     {
  198.         struct CommoditiesDetailWinData *cdwd = INST_DATA(cl, obj);
  199.         APTR parent;
  200.  
  201.         cdwd->cdwd_CxSubList = cxsublist;
  202.         CopyMem(cxmoretext, cdwd->cdwd_CxSubMoreText, sizeof(cdwd->cdwd_CxSubMoreText));
  203.  
  204.         parent = (APTR)GetTagData(MUIA_Window_ParentWindow, (ULONG)NULL, msg->ops_AttrList);
  205.  
  206.         set(obj, MUIA_Window_ActiveObject, cxmoretext[4]);
  207.  
  208.         DoMethod(parent,        MUIM_Window_AddChildWindow, obj);
  209.         DoMethod(obj,           MUIM_Notify,              MUIA_Window_CloseRequest, TRUE,  MUIV_Notify_Application, 5, MUIM_Application_PushMethod, parent, 2, MUIM_Window_RemChildWindow, obj);
  210.         DoMethod(cxmoretext[4], MUIM_Notify,              MUIA_Pressed            , FALSE, obj,                     1, MUIM_CommoditiesDetailWin_CxFlagsMore);
  211.     }
  212.  
  213.     return (ULONG)obj;
  214. }
  215.  
  216. static ULONG __saveds mDispose( struct IClass *cl,
  217.                                 Object *obj,
  218.                                 struct opSet *msg )
  219. {
  220.     struct CommoditiesDetailWinData *cdwd = INST_DATA(cl, obj);
  221.  
  222.     set(obj, MUIA_Window_Open, FALSE);
  223.     DoMethod(cdwd->cdwd_CxSubList, MUIM_NList_Clear);
  224.  
  225.     return (DoSuperMethodA(cl, obj, msg));
  226. }
  227.  
  228. static ULONG __saveds mSet( struct IClass *cl,
  229.                             Object *obj,
  230.                             Msg msg )
  231. {
  232.     struct CommoditiesDetailWinData *cdwd = INST_DATA(cl, obj);
  233.     struct TagItem *tags, *tag;
  234.  
  235.     for (tags = ((struct opSet *)msg)->ops_AttrList; tag = NextTagItem(&tags); ) {
  236.         switch (tag->ti_Tag) {
  237.             case MUIA_Window_ParentWindow:
  238.                 DoMethod(obj, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, MUIV_Notify_Application, 5, MUIM_Application_PushMethod, (APTR)tag->ti_Data, 2, MUIM_Window_RemChildWindow, obj);
  239.                 break;
  240.  
  241.             case MUIA_CommoditiesDetailWin_Commodity:
  242.                 cdwd->cdwd_Commodity = (struct CxEntry *)tag->ti_Data;
  243.                 SetDetails(cl, obj, (struct CxEntry *)tag->ti_Data);
  244.                 break;
  245.         }
  246.     }
  247.  
  248.     return (DoSuperMethodA(cl,obj,msg));
  249. }
  250.  
  251. static ULONG __saveds mCxFlagsMore( struct IClass *cl,
  252.                                     Object *obj,
  253.                                     Msg msg )
  254. {
  255.     struct CommoditiesDetailWinData *cdwd = INST_DATA(cl, obj);
  256.     APTR flagsWin;
  257.  
  258.     if (flagsWin = FlagsWindowObject,
  259.             MUIA_Window_Title, "Commodity Flags",
  260.             MUIA_Window_ParentWindow, obj,
  261.         End) {
  262.         DoMethod(flagsWin, MUIM_FlagsWin_ShowFlags, cdwd->cdwd_Commodity->cxe_Addr->mco_Flags, MUIV_FlagsWin_FlagsType_Byte, brokerFlags, NULL, "bc_Flags");
  263.     }
  264.  
  265.     return 0;
  266. }
  267.  
  268. ULONG __asm __saveds CommoditiesDetailWinDispatcher( register __a0 struct IClass *cl,
  269.                                                      register __a2 Object *obj,
  270.                                                      register __a1 Msg msg )
  271. {
  272.     switch (msg->MethodID) {
  273.         case OM_NEW:                                return (mNew(cl, obj, (APTR)msg));
  274.         case OM_DISPOSE:                            return (mDispose(cl, obj, (APTR)msg));
  275.         case OM_SET:                                return (mSet(cl, obj, (APTR)msg));
  276.         case MUIM_CommoditiesDetailWin_CxFlagsMore: return (mCxFlagsMore(cl, obj, (APTR)msg));
  277.     }
  278.  
  279.     return (DoSuperMethodA(cl, obj, msg));
  280. }
  281.  
  282.